var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/configComponent/common.tsx
var common_exports = {};
__export(common_exports, {
  LayConfWrap: () => import_util.LayConfWrap,
  convertHelpValues: () => convertHelpValues,
  fomatValues: () => fomatValues,
  formFomatValues: () => formFomatValues,
  getComp: () => getComp,
  getCompPorps: () => getCompPorps,
  getObjValue: () => getObjValue,
  getProperty: () => getProperty,
  getSubscribeFn: () => getSubscribeFn,
  isHelpField: () => isHelpField,
  isValueLabel: () => isValueLabel,
  listToObj: () => listToObj,
  parseFunction: () => parseFunction,
  setObjValue: () => setObjValue
});
module.exports = __toCommonJS(common_exports);
var import_util = require("../util");
var import_baseConfig = require("./config/baseConfig");
var emptyArray = [];
function getComp(item) {
  if (!item.xtype)
    return { instance: import_baseConfig.Comp_Info["Input"].instance };
  if (typeof item.xtype === "function")
    return { instance: item.xtype };
  if (item.xtype && typeof item.xtype === "object" && item.xtype.render && item.xtype.$$typeof)
    return { instance: item.xtype };
  return function(xtype, type) {
    if (import_baseConfig.Comp_Info[xtype]) {
      if (xtype === "Input" && ["prc", "amt", "amount", "qty", "rate", "percent"].includes(type) && import_baseConfig.Comp_Info["InputNumber"]) {
        return { instance: import_baseConfig.Comp_Info["InputNumber"].instance, props: import_baseConfig.Comp_Info["InputNumber"].defaultProps };
      }
      return { instance: import_baseConfig.Comp_Info[xtype].instance, props: import_baseConfig.Comp_Info[xtype].defaultProps };
    }
    const [ins, props] = (0, import_util.getRegisterComponentWithProps)(xtype);
    if (ins) {
      return {
        instance: ins,
        props
      };
    }
    return { instance: import_baseConfig.Comp_Info["Input"].instance };
  }(item.xtype, item.type);
}
function getCompPorps(item, config) {
  const p = config;
  let t = Object.keys(p).reduce((acc, curr) => {
    acc[curr] = item[curr] ? item[curr] : p[curr]["defaultValue"];
    return acc;
  }, item.antProps || {});
  p["data"] && (t["data"] = (item == null ? void 0 : item.data) || emptyArray);
  (item.xtype === "Checkbox" || item.xtype === "Checkbox") && delete t.value;
  return t;
}
function fomatValues(name, type, opt, key, initVals) {
  let vals = initVals;
  return merge;
  function merge(values) {
    if (typeof vals !== typeof values) {
      vals = values || vals;
    } else if (Array.isArray(vals)) {
      vals = vals.concat(values);
    } else if (typeof vals === "object") {
      vals = { ...vals, ...values };
    } else {
      vals = values;
    }
    if (!values)
      return {
        [name]: {
          [type]: vals ? {
            key,
            [opt]: vals
          } : { key }
        }
      };
    return merge;
  }
}
function formFomatValues(key, initVals) {
  let vals = {};
  let optType = "newRow";
  if (Object.prototype.toString.call(initVals) === "[object Object]") {
    initVals = [initVals];
  }
  if (Array.isArray(initVals)) {
    vals = initVals.reduce((p, n) => ({ ...p, ...n }), {});
    return {
      ["form"]: {
        key,
        [vals[key] ? "modifiedRow" : "newRow"]: vals
      }
    };
  }
  return merge;
  function merge(values) {
    if (typeof vals !== typeof values) {
      vals = values || vals;
    } else if (Array.isArray(vals)) {
      vals = vals.concat(values);
    } else if (typeof vals === "object") {
      vals = { ...vals, ...values };
    } else {
      vals = values;
    }
    if (!values) {
      return {
        ["form"]: vals ? {
          key,
          [optType]: vals
        } : { key }
      };
    }
    if (values[key])
      optType = "modifiedRow";
    return merge;
  }
}
function listToObj(c) {
  if (!c)
    return {};
  return c.reduce((acc, item) => {
    acc[item.name] = item;
    return acc;
  }, {});
}
function getProperty(o, keys) {
  if (typeof keys === "string" || typeof keys === "number") {
    return o && o[keys];
  }
  for (let i = 0; i < keys.length; i++) {
    if (!o)
      return;
    o = o[keys[i]];
  }
  return o;
}
function parseFunction(str) {
  if (str && typeof str === "string") {
    return (...args) => {
      try {
        const fn = new Function("return " + str)();
        return fn(...args);
      } catch (error) {
        console.log("erro:======", error, str);
      }
    };
  }
  return str;
}
function getObjValue(obj, pathKeys) {
  return import_util.iup.getObjValue(obj, pathKeys);
}
function setObjValue(obj, pathKeys, value) {
  import_util.iup.setObjValue(obj, pathKeys, value);
}
function getSubscribeFn(outRef) {
  return (fn, type, name) => {
    var _a, _b, _c, _d;
    if (!outRef.current._compIns) {
      return () => {
      };
    }
    if (name && name.length > 0) {
      const arr = import_util.iup.isArray(name) ? name : [name];
      const loop = (obj, prevKey = "") => Object.keys(obj).some((k) => {
        if (import_util.iup.isObject(obj[k]) && loop(obj[k], k)) {
          return true;
        }
        return arr.includes(prevKey ? `${prevKey}.${k}` : k);
      });
      return (_b = (_a = outRef.current).innerSubscribe) == null ? void 0 : _b.call(
        _a,
        (p) => {
          fn({ ...p, name });
        },
        type,
        ({ args }) => loop(args[0])
      );
    } else {
      return (_d = (_c = outRef.current).innerSubscribe) == null ? void 0 : _d.call(_c, fn, type);
    }
  };
}
function isHelpField(type) {
  var _a;
  return import_util.iup.isString(type) && ((_a = (0, import_util.getRegisterComponentWithProps)(type)[2]) == null ? void 0 : _a.isHelp);
}
function isValueLabel(item) {
  return import_util.iup.isObject(item) && item.hasOwnProperty("value") && item.hasOwnProperty("label");
}
function convertHelpValues(initValues) {
  Object.keys(initValues).forEach((k) => {
    const originValue = initValues[k];
    if ((originValue == null ? void 0 : originValue.length) && isValueLabel(originValue[0])) {
      setObjValue(initValues, k, originValue.map((item) => item.value).join());
    } else if (isValueLabel(originValue)) {
      setObjValue(initValues, k, originValue.value);
    }
  });
  return initValues;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  LayConfWrap,
  convertHelpValues,
  fomatValues,
  formFomatValues,
  getComp,
  getCompPorps,
  getObjValue,
  getProperty,
  getSubscribeFn,
  isHelpField,
  isValueLabel,
  listToObj,
  parseFunction,
  setObjValue
});
